/**
 * 用户角色
 *
 * 文件命名格式：zmn.模块名称.表名称.功能.jas
 * @author duanzuocai
 * @since 2018/10/18
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;

    var cols = [
        [
            {field: 'roleId', type: 'checkbox', fixed: 'left', width: 50, align: 'center'},
            {field: 'roleSort', title: '角色排序', width: 300, align: 'center', unresize: true, sort: false},
            {field: 'roleId', title: '角色ID', width: 300, align: 'center', unresize: true, sort: false},
            {field: 'roleName', title: '角色名称', width: 300, align: 'center', unresize: true, sort: false},
            {
                field: 'roleStatusstatus', title: '状态', width: 300, align: 'center', unresize: true, templet: function (d) {
                    return zmnEnum.STATUS[d.roleStatus];
                }
            },
            {field: 'roleRemark', title: '角色说明',  align: 'center', unresize: false, sort: false}
        ]
    ];
    table.render({
        elem: "#zmn-role-staff-table",
        toolbar: "#zmn-role-staff-table-tool",
        title: "分类列表",
        data: json.items,
        limit: json.pageSize,
        cols: cols,
        page: true,
        height: 'full-120'
    });

    laypage.render(zmnPage.laypageOptions(json));

    var ids = new Array();

    // 选择（全选或单选）
    table.on("checkbox(zmn-role-staff-table)", function () {
        ids = zmnPage.layIdsChecked(json.items, "roleId");
    });

    // 删除、添加
    table.on("toolbar(zmn-role-staff-table)", function (obj) {
        if (obj.event == "del" && ids.length === 0) {
            return layer.alert("请选择至少一个角色！");
        }
        if (obj.event == "del") {
            zmnPage.ajaxSimple("/mc/role/staff/del.action", {ids: ids.join(","), staffId: json.staffId}, 1500);
        }
        if (obj.event == "add") {
            zmnPage.ajaxSimple("/mc/role/staff/add.action", {ids: ids.join(","), staffId: json.staffId}, 1500);
        }
    });

    // 修改排序
    table.on("edit(zmn-role-staff-table)", function (obj) {
        zmnPage.laySort(obj, "/mc/role/updateSort.action", obj.data.roleId);
    });

    //对外暴露的接口
    exports('art_role_staff_list', {});
});